package ru.tennisworld.user.controllers;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;
import ru.tennisworld.user.controller.TennisUserController;
import ru.tennisworld.user.dto.RegistrationTennisUserRequestDto;
import ru.tennisworld.user.dto.TennisUserFullInfoResponseDto;
import ru.tennisworld.user.dto.TennisUserResponseDto;
import ru.tennisworld.user.dto.UpdateTennisUserRequestDto;
import ru.tennisworld.user.service.TennisUserControllerService;
import ru.tennisworld.user.service.ValidationControllerService;

import java.util.List;

@RestController
public class TennisUserControllerImpl implements TennisUserController {

    @Autowired
    private ValidationControllerService validationControllerService;

    @Autowired
    private TennisUserControllerService tennisUserControllerService;

    private static final Logger LOG = LoggerFactory.getLogger(TennisUserControllerImpl.class);

    @Override
    public ResponseEntity<List<TennisUserResponseDto>> getUserReferenceList(List<String> usernameList) {
        LOG.info("operation=TennisUserControllerImpl.getUserReferenceList, action=start, usernameList={}", usernameList);
        List<TennisUserResponseDto> result = tennisUserControllerService.getUserReference(usernameList);
        LOG.info("operation=TennisUserControllerImpl.getUserReferenceList, action=end, result={}", result);
        return new ResponseEntity<>(result, HttpStatus.OK);
    }

    @Override
    public ResponseEntity<TennisUserFullInfoResponseDto> getUserInfo(String username) {
        LOG.info("operation=TennisUserControllerImpl.getUserInfo, action=start, userId={}", username);
        TennisUserFullInfoResponseDto result = tennisUserControllerService.getUserInfo(username);
        LOG.info("operation=TennisUserControllerImpl.getUserInfo, action=end, result={}", result);
        return new ResponseEntity<>(result, HttpStatus.OK);
    }

    @Override
    public ResponseEntity<TennisUserResponseDto> registrationUser(RegistrationTennisUserRequestDto request) {
        LOG.info("operation=TennisUserControllerImpl.registrationUser, action=start, request={}", request);
        TennisUserResponseDto result = tennisUserControllerService.createNewUser(request);
        LOG.info("operation=TennisUserControllerImpl.registrationUser, action=end, result={}", result);
        return new ResponseEntity<>(result, HttpStatus.OK);
    }

    @Override
    public ResponseEntity<TennisUserFullInfoResponseDto> updateUserMainInfo(String username, UpdateTennisUserRequestDto request) {
        LOG.info("operation=TennisUserControllerImpl.updateUserMainInfo, action=start, request={}", username);
        validationControllerService.validateUpdateTennisUserRequest(request);
        TennisUserResponseDto result = tennisUserControllerService.updateTennisUser(username, request);
        LOG.info("operation=TennisUserControllerImpl.updateUserMainInfo, action=end, result={}", result);
        return null;
    }
}
